<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list1';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请重新选择！','error');
	}
}
$return=array();
$tabs=array(
	//array('op'=>'list0','title'=>'未核销'),
	array('op'=>'list1','title'=>'已核销'),
	array('op'=>'list2','title'=>'已取消'),
);
$return['isverify']=array('0'=>'未核销','1'=>'已核销','2'=>'已取消');
if($_RQ['op']=='list0'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isverify']=0;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','orderid','verifycode','storeid','mid','verifier','isverify','verifytime');
	$list=pdo_getslice('jy_aligroup_groups_verify',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$member=pdo_get('jy_weishop_member',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$order=pdo_get('jy_aligroup_groups_order',array('id'=>$item['orderid'],'uniacid'=>$_SESSION['uniacid']));
			$group=pdo_get('jy_aligroup_groups',array('id'=>$order['groupid'],'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_weishop_goods',array('id'=>$order['goodsid'],'uniacid'=>$_SESSION['uniacid']));
			$corps=pdo_get('jy_aligroup_groups_corps',array('id'=>$order['cid'],'uniacid'=>$_SESSION['uniacid']));

			//订单编号	 下单时间			  
			$item['orderno']=$order['orderno'];
			$item['ordertime']=$order['createtime'];
			$item['goodsprice']=$goods['price'];
			$item['orderprice']=$order['price'];
			$item['goodstitle']=$goods['title'];
			$item['orderstatus']=$order['status'];
			
			$item['realname']=$order['realname'];
			$item['mobile']=$order['mobile'];
			$item['grouptitle']=$group['title'];
			$item['corpstitle']=$corps['title'];
			$item['goodstitle']=$goods['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'orderno','title'=>'订单编号','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'goodsprice','title'=>'商品价格','type'=>'string'),
			array('name'=>'realname','title'=>'买家姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'买家电话','type'=>'string'),
			array('name'=>'orderprice','title'=>'金额','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'orderstatus','title'=>'状态','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'订单编号','type'=>'string','width'=>'40'),
			
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='list1'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
		$params['isverify']=1;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','orderid','verifycode','storeid','mid','verifier','isverify','verifytime');
	$list=pdo_getslice('jy_aligroup_groups_verify',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$member=pdo_get('jy_weishop_member',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$order=pdo_get('jy_aligroup_groups_order',array('id'=>$item['orderid'],'uniacid'=>$_SESSION['uniacid']));
			$group=pdo_get('jy_aligroup_groups',array('id'=>$order['groupid'],'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_weishop_goods',array('id'=>$order['goodsid'],'uniacid'=>$_SESSION['uniacid']));
			$corps=pdo_get('jy_aligroup_groups_corps',array('id'=>$order['cid'],'uniacid'=>$_SESSION['uniacid']));

			//订单编号	 下单时间			  
			$item['orderno']=$order['orderno'];
			$item['ordertime']=$order['createtime'];
			$item['goodsprice']=$goods['price'];
			$item['orderprice']=$order['price'];
			$item['goodstitle']=$goods['title'];
			$item['orderstatus']=$order['status'];
			
			$item['realname']=$order['realname'];
			$item['mobile']=$order['mobile'];
			$item['grouptitle']=$group['title'];
			$item['corpstitle']=$corps['title'];
			$item['goodstitle']=$goods['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'orderno','title'=>'订单编号','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'goodsprice','title'=>'商品价格','type'=>'string'),
			array('name'=>'realname','title'=>'买家姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'买家电话','type'=>'string'),
			array('name'=>'orderprice','title'=>'金额','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'orderstatus','title'=>'状态','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'订单编号','type'=>'string','width'=>15),
			
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='list2'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isverify']=2;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','orderid','verifycode','storeid','mid','verifier','isverify','verifytime');
	$list=pdo_getslice('jy_aligroup_groups_verify',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$member=pdo_get('jy_weishop_member',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$order=pdo_get('jy_aligroup_groups_order',array('id'=>$item['orderid'],'uniacid'=>$_SESSION['uniacid']));
			$group=pdo_get('jy_aligroup_groups',array('id'=>$order['groupid'],'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_weishop_goods',array('id'=>$order['goodsid'],'uniacid'=>$_SESSION['uniacid']));
			$corps=pdo_get('jy_aligroup_groups_corps',array('id'=>$order['cid'],'uniacid'=>$_SESSION['uniacid']));

			//订单编号	 下单时间			  
			$item['orderno']=$order['orderno'];
			$item['ordertime']=$order['createtime'];
			$item['goodsprice']=$goods['price'];
			$item['orderprice']=$order['price'];
			$item['goodstitle']=$goods['title'];
			$item['orderstatus']=$order['status'];
			
			$item['realname']=$order['realname'];
			$item['mobile']=$order['mobile'];
			$item['grouptitle']=$group['title'];
			$item['corpstitle']=$corps['title'];
			$item['goodstitle']=$goods['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'orderno','title'=>'订单编号','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'goodsprice','title'=>'商品价格','type'=>'string'),
			array('name'=>'realname','title'=>'买家姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'买家电话','type'=>'string'),
			array('name'=>'orderprice','title'=>'金额','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'orderstatus','title'=>'状态','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'订单编号','type'=>'string','width'=>15),
			
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}